import { request } from '../utils';
import buildService from './buildService';
import u from 'underscore';

let baseService = buildService('index');

export default {
  ...baseService,

  async basicInfo(id) {
    return request(
      baseService.requestHost + '/basicInfo/' + id,
      { method: 'GET' }
    );
  },

  async queryData(params) {
    let type = params.type;
    let searchParams = u.omit(params, 'type');
    if (params.type === 'sql') {
      return request(
        '/sql/select',
        { method: 'POST', data: searchParams }
      );
    }
  },

  async metaTypes() {
    return request(
      '/metadata/allTypes',
      { method: 'GET' }
    );
  },

  async updateIndex(params) {
    return request(
      '/index',
      { method: 'POST', data: { ...params }}
    );
  }
}
